﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Linq;
using DevComponents.DotNetBar;
using DBManager.DanhMucHeThong.BAL;
using DBManager.DanhMucHeThong.Entities;
namespace MamNonTuoiTho.Form.QuanLyHocSinh
{
    public partial class frmXa : DevComponents.DotNetBar.Office2007Form
    {
        public frmXa()
        {
            InitializeComponent();            
            Huyen_Load();
            Xa_Load();
        }
        #region LoadData
        private void Huyen_Load()
        {
            List<DanhMuc_Ent> lstHuyen = new List<DanhMuc_Ent>();
            DanhMuc_Ent TatCa = new DanhMuc_Ent();
            TatCa.DanhMucID = 0;
            TatCa.LoaiDanhMuc = "TatCa";
            TatCa.TenDanhMuc = "Tất cả";
            lstHuyen.Add(TatCa);
            DanhMuc_BAL.DanhMuc_GetItems("Huyen").ForEach(x => lstHuyen.Add(x));
            cbxHuyen.DataSource = lstHuyen;
        }
        private void Xa_Load()
        {
            int DanhMucID = int.Parse(cbxHuyen.SelectedValue.ToString());
            grvXa.AutoGenerateColumns = false;
            if (DanhMucID == 0)
            {
                grvXa.DataSource = DanhMuc_BAL.DanhMuc_GetItems("Xa");
            }
            else
            {
                List<DanhMuc_Ent> lstXa = DanhMuc_BAL.DanhMuc_GetItems("Xa");
                var query = from Xa in lstXa                                   
                            where Xa.DanhMucParentID == DanhMucID
                            select Xa;
                grvXa.DataSource = query.ToList();
            }
        }
        #endregion LoadData

        private void cmdThem_Click(object sender, EventArgs e)
        {
            frmXa_Edit Xa_Edit = new frmXa_Edit();
            Xa_Edit.FormClosed += new FormClosedEventHandler(Xa_Edit_FormClosed);
            Xa_Edit.Show();
        }

        void Xa_Edit_FormClosed(object sender, FormClosedEventArgs e)
        {
            Xa_Load();
        }

        private void cbxHuyen_SelectedValueChanged(object sender, EventArgs e)
        {
            Xa_Load();
        }

        private void cmdChinhSua_Click(object sender, EventArgs e)
        {
            try
            {
                int DanhMucID = int.Parse(grvXa.SelectedRows[0].Cells["DanhMucID"].Value.ToString());
                //frmHuyen_Edit Huyen_Edit = new frmHuyen_Edit();
                //Huyen_Edit.DanhMucID = DanhMucID;
                //Huyen_Edit.Huyen_Load();
                //Huyen_Edit.FormClosed += new FormClosedEventHandler(Huyen_Edit_FormClosed);
                //Huyen_Edit.Show();
            }
            catch (Exception ex)
            {                
                throw;
            }
        }
    }
}